using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DTO
{
    /// <summary> 
    ///Author: nnamthach@gmail.com 
    /// <summary>

    public class StatusInfo
    {
        #region Local Variable
        public enum Field
        {
            ID,
            Code,
            Name,
            NameVN,
            Enabled
        }
        private Int32 _ID;
        private String _Code;
        private String _Name;
        private String _NameVN;
        private Int32 _Enabled;

        public Int32 ID { get { return _ID; } set { _ID = value; } }
        public String Code { get { return _Code; } set { _Code = value; } }
        public String Name { get { return _Name; } set { _Name = value; } }
        public String NameVN { get { return _NameVN; } set { _NameVN = value; } }
        public Int32 Enabled { get { return _Enabled; } set { _Enabled = value; } }

        #endregion LocalVariable

        #region Constructor
        public StatusInfo()
        {
            _ID = 0;
            _Code = "";
            _Name = "";
            _NameVN = "";
            _Enabled = 1;
        }
        public StatusInfo(
        Int32 ID,
        String Code,
        String Name,
        String NameVN,
        Int32 Enabled
        )
        {
            _ID = ID;
            _Code = Code;
            _Name = Name;
            _NameVN = NameVN;
            _Enabled = Enabled;
        }
        public StatusInfo(DataRow dr)
        {
            if (dr != null)
            {
                _ID = dr[Field.ID.ToString()] == DBNull.Value ? 0 : Convert.ToInt32(dr[Field.ID.ToString()]);
                _Code = dr[Field.Code.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.Code.ToString()]);
                _Name = dr[Field.Name.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.Name.ToString()]);
                _NameVN = dr[Field.NameVN.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.NameVN.ToString()]);
                _Enabled = dr[Field.Enabled.ToString()] == DBNull.Value ? 0 : Convert.ToInt32(dr[Field.Enabled.ToString()]);
            }
        }
        public StatusInfo(StatusInfo objEntr)
        {
            _ID = objEntr.ID;
            _Code = objEntr.Code;
            _Name = objEntr.Name;
            _NameVN = objEntr.NameVN;
            _Enabled = objEntr.Enabled;
        }
        #endregion Constructor

        #region InitTable
        public DataTable ToDataTable()
        {
            DataTable dt = new DataTable("Status");
            dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.ID.ToString(), typeof(Int32)),
				new DataColumn(Field.Code.ToString(), typeof(String)),
				new DataColumn(Field.Name.ToString(), typeof(String)),
				new DataColumn(Field.NameVN.ToString(), typeof(String)),
				new DataColumn(Field.Enabled.ToString(), typeof(Int32))
			});
            return dt;
        }
        public DataRow ToDataRow(DataTable dt)
        {
            DataRow row = dt.NewRow();
            row[Field.ID.ToString()] = _ID;
            row[Field.Code.ToString()] = _Code;
            row[Field.Name.ToString()] = _Name;
            row[Field.NameVN.ToString()] = _NameVN;
            row[Field.Enabled.ToString()] = _Enabled;
            return row;
        }
        #endregion InitTable
    }
}
